package com.tihi.uiautomator;

import com.tihi.handsuiviewer.AppDef;
import com.tihi.util.AppUtils;
import com.tihi.util.ShellUtils;
import com.tihi.util.ShellUtils.CommandResult;
import com.tihi.util.TihiAsyncTask;
import com.tihi.util.TihiAsyncTask.IAsyncTaskListener;

/**
 * uiautomator 生成 uidump.xml文件
 * @author duantihi
 *
 * @date 2016-1-31 下午5:24:31
 */
public class UIAutomator {
	
	private IShellCmdListener listener;
	public UIAutomator (IShellCmdListener listener) {
		this.listener = listener;
	}
	
	public void submit() {
 		new TihiAsyncTask<CommandResult>(new IAsyncTaskListener<CommandResult>() {

			@Override
			public CommandResult onTask() {
				if(AppUtils.isFileExist(AppDef.UIDUMP_XML_PATH)) {
					AppUtils.delFile(AppDef.UIDUMP_XML_PATH);
				}
				return ShellUtils.execCommand(AppDef.UI_DUMP_CMD, true, true);
			}

			@Override
			public void onResult(final CommandResult t) {
				if(listener != null) {
					if(AppUtils.isFileExist(AppDef.UIDUMP_XML_PATH)) {
						listener.onResult(true);
					}else {
						listener.onResult(false);
					}
				}
			}
		}).submit();
	}

}
